package com.wwj.framework.utils;

/**
 * Created by xya on 16-10-14.
 */
public class ReturnData {

    private static final String OK = "ok";

    private static final String ERROR = "error";

    /**
     * 元数据
     */
    private Meta meta;

    /**
     * 返回数据
     */
    private Object data;

    /**
     * 返回数据扩展字段
     */
    private Object extra;

    public ReturnData success() {
        this.meta = new Meta(true, OK);
        return this;
    }

    public ReturnData success(Object data) {
        this.meta = new Meta(true, OK);
        this.data = data;
        return this;
    }

    public ReturnData success(Object data,Object extra) {
        this.meta = new Meta(true, OK);
        this.data = data;
        this.extra = extra;
        return this;
    }

    public ReturnData success(String message, Object data,Object extra) {
        this.meta = new Meta(true, message);
        this.data = data;
        this.extra = extra;
        return this;
    }

    public ReturnData success(String message, Object data) {
        this.meta = new Meta(true, message);
        this.data = data;
        return this;
    }

    public ReturnData failure() {
        this.meta = new Meta(false, ERROR);
        return this;
    }

    public ReturnData failure(String message) {
        this.meta = new Meta(false, message);
        return this;
    }

    public ReturnData failure(String message, String errorCode) {
        this.meta = new Meta(false, message, errorCode);
        return this;
    }

    public Meta getMeta() {
        return meta;
    }

    public void setMeta(Meta meta) {
        this.meta = meta;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Object getExtra() {
        return extra;
    }

    public void setExtra(Object extra) {
        this.extra = extra;
    }

    public class Meta {

        private boolean success;

        private String message;

        private String errorCode;

        public Meta(boolean success, String message) {
            this.success = success;
            this.message = message;
        }

        public Meta(boolean success, String message, String errorCode) {
            this.success = success;
            this.message = message;
            this.errorCode = errorCode;
        }

        public boolean isSuccess() {
            return success;
        }

        public void setSuccess(boolean success) {
            this.success = success;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public String getErrorCode() {
            return errorCode;
        }

        public void setErrorCode(String errorCode) {
            this.errorCode = errorCode;
        }
    }
}
